<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar shadow">
        <div class="btn-group tool-button mt5">
            <el-input placeholder="用户搜索" v-model="pageForm.userSearch" @keyup.enter.native="pageData"
                      size="medium"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-input placeholder="代理搜索" v-model="pageForm.inviterSearch" @keyup.enter.native="pageData"
                      size="medium"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-date-picker
                    v-model="searchDate"
                    type="daterange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    unlink-panels
                    align="right"
                    size="medium"
                    value-format="yyyy-MM-dd"
                    style="width: 400px">
            </el-date-picker>
        </div>
        <!--搜索按钮-->
        <div class="btn-group tool-button mt5">
            <el-button slot="append" icon="el-icon-search" @click="doSearch" size="medium"></el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                @sort-change='pageOrder'
                size="small"
                header-align="center"
                style="width: 100%"
                @selection-change="handleSelectionChange"
                :default-sort="{prop: 'opAt', order: 'descending'}">

            <el-table-column label="日期"
                             header-align="left"
                             prop="date"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="有效金额"
                             header-align="left"
                             prop="count"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="手机号码"
                             header-align="left"
                             prop="phone"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="用户名称"
                             header-align="left"
                             prop="nickName"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="用户名"
                             header-align="left"
                             prop="userName"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="自返水"
                             header-align="left"
                             prop="selfIncome"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="代理手机号码"
                             header-align="left"
                             prop="inviterPhone"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="代理昵称"
                             header-align="left"
                             prop="inviterNickName"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="代理用户名"
                             header-align="left"
                             prop="inviterUserName"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="代理返水"
                             header-align="left"
                             prop="agentIncome"
                             :show-overflow-tooltip="true">
            </el-table-column>

            <el-table-column label="创建时间"
                             header-align="center"
                             align="center"
                             prop="ctAt">
                <template slot-scope="scope">
                    {{formatAt(scope.row.ctAt)}}
                </template>
            </el-table-column>

        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>
</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            return {
                searchDate: [],
                pickerOptions: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                pageForm: {
                    userSearch: "",
                    inviterSearch: "",
                    searchDate: "",
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    pageOrderName: "opAt",
                    pageOrderBy: "descending"
                },
                tableData: [],
                loading: false,
            }
        },
        methods: {
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                let self = this;
                sublime.showLoadingbar();//显示loading
                if (self.searchDate) {
                    self.pageForm.searchDate = self.searchDate.toString();
                } else {
                    self.pageForm.searchDate = "";
                }
                $.post(base + "/platform/user/account/income/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code === 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val).format("YYYY-MM-DD HH:mm");
                return "";
            },
            handleSelectionChange: function (val) {
                this.selectData = val;
            }
        },
        created: function () {
            this.pageData();
        }
    });
</script>
<!--#
}
#-->